package com.bing.bing.servi;

import com.bing.bing.mapper.MyMapper;
import com.bing.bing.pojo.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class MyServiceImpl implements MyService
{
    @Autowired(required = false)
    MyMapper myMapper;

    @Autowired
    DuoYuServiceImpl duoYuServiceImpl;

/*    @Autowired
    MyTestService myTestService;*/
    @Override
    public List<Student> getList()
    {
        Student tt = new Student();
        tt.setId(11);
        tt.setName("biu");
        tt.setAge(22);
        tt.setAddr("gggg");
        List<Student> students = myMapper.select(tt);
        return students;
    }

    public Student findById(Integer id)
    {
        return myMapper.selectByPrimaryKey(id);
    }

    public List<Student> findByxx(String name, String addr)
    {
        Student student = new Student();
        if(name != null)
        {
            student.setName(name);
        }
        if(addr != null)
        {
            student.setAddr(addr);
        }
        return myMapper.select(student);
    }


    @Override
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public void saveUser(String name)
    {

        String[] split = name.split(",");
        for(String username : split)
        {

            try
            {
                duoYuServiceImpl.addUser(username);
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }

        }

    }
}
